﻿package blob.mechanisms
{
    import blob.characters.*;
    import org.flixel.*;

    public class Fan extends FlxSprite implements Mechanism
    {
        private var fanPNG:Class;
        private var fanPNGLeft:Class;
        private var fanPNGRight:Class;
        private var _size:uint;
        private var _direction:uint;
        private var _reach:uint;
        private var _x:int;
        private var _y:int;
        private var _force:uint;

        public function Fan(param1:uint, param2:uint, param3:uint, param4:int, param5:int, param6:uint = 20)
        {
            var _loc_7:Class = null;
            var _loc_8:int = 0;
            var _loc_9:int = 0;
            this.fanPNG = Fan_fanPNG;
            this.fanPNGLeft = Fan_fanPNGLeft;
            this.fanPNGRight = Fan_fanPNGRight;
            this._size = param1;
            this._direction = param2;
            this._reach = param3;
            this._x = param4;
            this._y = param5;
            this._force = param6;
            if (param2 == FlxObject.LEFT)
            {
                _loc_7 = this.fanPNGLeft;
                _loc_8 = 260;
                this._reach = this._reach * 2;
                _loc_9 = 41;
            }
            else if (param2 == FlxObject.RIGHT)
            {
                _loc_7 = this.fanPNGRight;
                _loc_8 = 260;
                this._reach = this._reach * 2;
                _loc_9 = 41;
            }
            else
            {
                _loc_7 = this.fanPNG;
                _loc_8 = 41;
                _loc_9 = 130;
            }
            super(param4, param5);
            loadGraphic(_loc_7, true, true, _loc_8, _loc_9);
            addAnimation("blowMe", [0, 1], 4, true);
            solid = true;
            return;
        }// end function

        public function activate(param1:Character) : void
        {
            if (param1.size() <= this._size)
            {
                if (this._direction == FlxObject.LEFT)
                {
                    param1.applyForce(-1 * ((this._reach - (this._x + width - (param1.x + param1.width))) / this._reach) * this._force);
                }
                else if (this._direction == FlxObject.RIGHT)
                {
                    param1.applyForce((this._reach - (param1.x - this._x)) / this._reach * this._force);
                }
                else if (this._direction == FlxObject.UP)
                {
                    param1.velocity.y = param1.velocity.y - (this._reach - (this._y - param1.y)) / this._reach * this._force;
                }
                else if (this._direction == FlxObject.DOWN)
                {
                    param1.velocity.y = param1.velocity.y + (this._reach - (this._y - param1.y)) / this._reach * this._force;
                }
            }
            return;
        }// end function

        public function toggle() : void
        {
            return;
        }// end function

        override public function update() : void
        {
            play("blowMe");
            return;
        }// end function

    }
}
